<style>
    input[name='shop_id']{
        display: none;
    }
</style>
<?php $form=$this->beginWidget('CActiveForm', array(
                            'id'=>'branch-group-form',
                            'enableClientValidation'=>true,
                            'clientOptions'=>array(
                                'validateOnSubmit'=>true,
                            ),
                            //'enableAjaxValidation'=>true,
                            'htmlOptions' => array('class' => 'stdform', 'enctype' => 'multipart/form-data')
                        )); ?>
<?php $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'branch-grid',
    'dataProvider'=>$dataProvider,
    'filter'=>$model,
    'ajaxUpdate'=> true,
    //'template' => "{items} {pager}",
    'itemsCssClass' => 'table table-striped table-bordered',
    'pagerCssClass' => 'pagination pagination-centered',
    'pager'=>array(
        'class'=>'CLinkPager',
        'htmlOptions' => array(
            'class' => '',
        ),
        'hiddenPageCssClass' => 'disabled',
        'selectedPageCssClass' => 'active',
        'maxButtonCount'    =>  8,
        'header'            => FALSE,

    ),
    'loadingCssClass' => '',
    'beforeAjaxUpdate'=>'function(id,options){
        $("#ajax-loading").fadeIn();    
    }',
    'afterAjaxUpdate'=>'function(id,options){
        $("#ajax-loading").fadeOut();    
    }',
    'columns'=>array(
      array(
        'header'=>'No.',
        'value'=>'$this->grid->dataProvider->pagination->currentPage * $this->grid->dataProvider->pagination->pageSize + ($row+1)',
      ),
        array(
            'name' => 'id',
            'type'      =>  'html',
            'value' => '$data->id',
            'headerHtmlOptions' => array('style' => 'width: 40px'),
        ),
        array(
            'name' => 'image',
            'type'      =>  'html',
            'value' => 'CHtml::image($data->getImageUrl("80"))',
            'filter' => FALSE,
        ),
        array(
            'header'=>'Gộp các branch',
            'class'=>'CDataColumn',
            'type'=>'raw',
            'htmlOptions'=>array('style'=>'text-align:center'),
            'value' => 'CHtml::checkBox("branch_id[]", $data->check_branch, array("value"=>$data->id,"id"=>"branch_id_".$data->id,"onchange" => "checkbox_checked($(this))"))',
        ),
        array(
            'header'=>'Chọn shop để gộp',
            'class'=>'CDataColumn',
            'type'=>'raw',
            'htmlOptions'=>array('style'=>'text-align:center;'),
            'value' => 'CHtml::radioButton("shop_id", $data->check_branch, array("value"=>$data->shop["id"],"id"=>"branch_in_shop_".$data->id))',
        ),
        array(
            'name' => 'shop_name',
            'type'      =>  'html',
            'value' => '"<div>".$data->shop["name"]."</div>"',
        ),
        array(
            'name' => 'name',
            'type'      =>  'html',
            'value' => '"<div>".$data->name."</div><div class=\"grid-address-full\">".$data->siblingLabelList."</div>"',
        ),
        array(
            'name' => 'cats',
            'type'      =>  'raw',
            'value' => '$data->catLabelList',
            'filter' => PostCat::model()->data,
        ),
        array(
            'name' => 'city_id',
            'type'      =>  'raw',
            'value' => '$data->city->name',
            'filter' => City::model()->data,
        ),
        array(
            'name' => 'district_id',
            'type'      =>  'raw',
            'value' => '$data->district->name',
            'filter' => $districtsData,
        ),
        array(
            'name' => 'address',
            'type'      =>  'html',
            'value' => '$data->address',
        ),
        
        array(
            'name' => 'status',
            'type'      =>  'raw',
            'value' => '$data->statusLabel',
            'filter' => $model->statusData,
        ),
        array(
            'class'=>'CButtonColumn',
            'template'=>'{update}',
        ),
    ),
)); ?>
        <?php echo CHtml::button('Save', array('class' => 'btn btn-info', 'id' => 'save-group-branch','onclick' => 'save()')); ?>
<?php $this->endWidget(); ?>
<script>
    function save(){
        var check = $('input:checkbox:checked').length;
        var button = $('input:radio:checked').length;
        if(button > 0 && check > 1)
                $("#branch-group-form").submit();
        else alert("bạn phải nhập đầy đủ thông tin");
    }
    function checkbox_checked(event){
        var val = event.val();
        if(event.is(':checked'))
            $("#branch_in_shop_"+val).show();
        else 
            $("#branch_in_shop_"+val).hide();
    }
</script>